import BaseController from '../../core/controllers/Base.controller';
import storageApi from '../../core/storage/storage';
import './actualSituation.scss';

@Inject('$log', '$rootScope', 'actualSituationService', 'ngDialog', 'ngDialogService')
class ActualSituationController extends BaseController {
  constructor() {
    super();

    this.paginationService = this.actualSituationService;
    this.$setQueryCallback((res) => {
      this.actuaSituationData = res.rows;
    });

    this.mapParams = {
      orgId: $rootScope.orgId || storageApi.get('orgId'),
    };

    this.$paginationQuery();
  }

  $reset() {
    this.mapParams = {
      orgId: this.$rootScope.orgId || storageApi.get('orgId'),
    };
  }

  $delete(id) {
    this.ngDialogService.confirm('确定删除此数据吗？', id)
      .then((data) => {
        this.actualSituationService
          .delete([id])
          .then((res) => {
            if (res.success) {
              this.ngDialogService.alertSuccess(res.message);
              this.$paginationQuery();
            }
          });
      });
  }

  // 新增
  $addActualSituation(sysCtrl) {
    this.ngDialog.open({
      template: 'addActualSituationDialog',
      className: 'ngdialog-theme-default pa-in-out-registration',
      controllerAs: 'vm',
      controller($rootScope, $scope, ngDialogService) {
        'ngInject';

        this.sureBtnFn = () => {
          const reqData = {
            orgId: $rootScope.orgId || storageApi.get('orgId'),
            progressSituation: this.params.progressSituation,
          };
          sysCtrl.actualSituationService
            .save(reqData)
            .then((res) => {
              sysCtrl.$paginationQuery();
              ngDialogService.alertSuccess(res.message);
            });
          $scope.closeThisDialog();
        };
      },
    });
  }

  $viewDatail(id, sysCtrl) {
    this.ngDialog.open({
      template: 'actualSituationDetailDialog',
      className: 'ngdialog-theme-default pa-in-out-registration',
      controllerAs: 'vm',
      controller($scope, ngDialogService) {
        'ngInject';

        sysCtrl.actualSituationService
          .get(id)
          .then((res) => {
            if (res.success) {
              this.view = res.data;
            }
          });
      },
    });
  }

}

export default ActualSituationController;
